﻿$tab_list = $("#tab_factory");
$tab_order = $("#tab_order");
var lastIndex;
$("#tab_factory").datagrid({
    //---------------------------- 属性 Properties ----------------------------
    //请求类型 默认post
    method: "post",
    //请求url地址 默认null
    url: $tab_list.attr("data-url"),
    //是否开启隔行条纹 默认false
    striped: true,
    pagination: true,
    singleSelect: true,
    selectOnCheck: true,
    rowStyler: function (index, row) {
        if (row.TotalQty > 900) {
            return 'background-color:#6293BB';
            //这个方法支持return[class和样式对象]
            //return {class:'rowClass',style:'color:red'}
        }
    },
    //冻结列配置
    frozenColumns: [[
        { checkbox: true, field: 'ck' }
    ]],
    //列配置
    columns: [
        [{ title: "供应商", colspan: 3 }, { title: "呵呵" }],
        [{
            //字段名 map数据属性名 默认undefined
            field: 'OrderNo',
            //表头 默认undefined
            title: "订货单编号",
            //宽度 默认undefined
            width: 200,
            //是否排序 默认false
            sortable: true,
            //表头对齐 默认undefined ['left','right','center']
            halign: "center",
            //行对齐 默认undefined ['left','right','center']
            align: "left",
            //是否可调整大小 默认undefined
            resizable: true,
            //样式 默认undefined
            //value:列数据 the field value
            //row:行数据 the row record data
            //index:行索引 the row index
            styler: function (value, row, index) {
                if (value < 2) {
                    return "background-color:#ffee00;color:red;";
                    //这个方法支持return[class和样式对象]
                    //return {class:'cellClass',style:'color:red'}
                }
            },
            //设置默认触发排序的方式 默认undefined ['asc','desc']
            //不设置：以desc降序方式
            order: "desc",
            //本地排序 默认undefined
            //注意：dataGrid需配置remoteSort:false,column配置sortable:true
            //自带的排序支持number,string,不支持Object
            sorter: function (a, b) {
                return a - b;
            },
            //是否隐藏 默认undefined
            hidden: false,
            //列格式化方法 the cell formatter function
            //value:列数据 the field value
            //row:行数据 the row record data
            //index:行索引 the row index
            formatter: function (value, row, index) {
                return "<b>" + value + "</b> ";
            }
        },
            {
                field: 'TotalQty', title: "订单金额", width: 100, sortable: true, editor: "text", align: "right",
            },
            {
                field: 'Supplier',
                title: "供应商",
                width: 100,
                sortable: true,
                //格式化对象
                formatter: function (value, row, index) {
                    if (value) {
                        return value.Name;
                    }
                    return "";
                },
                //注意：如果该列数据源是Object需按以下方式排序
                //不一定要用显示的属性，也可以使用其他属性，看情况而定。
                sorter: function (a, b) {
                    return a.Name == b.Name ? 0 : a.Name > b.Name ? 1 : -1;
                }
            },
            { field: 'CreateDate', title: "创建日期", width: 100, editor: "datebox" }
        ]
    ],
    onSelect: function (index, row) {
        //ShowOrder(row.OrderNo);
        $tab_order.OrderGrid('searchByID', row.OrderNo);
    }
});

$tab_order.OrderGrid({
    url: $tab_order.attr("data-url"),
    saveData: function (jq) {
        alert('this is private');
    },
    toolbar: [{
        iconCls: 'icon-save',
        handler: function () {
            $tab_order.OrderGrid('saveData');
        }
    }]
});
